package com.crayon.util;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
 * UIBIND
 * @author kws
 *
 */
public class UIBIND {

	public static void bindView(View layout,int nId,View.OnClickListener clickListener){
		View v = layout.findViewById(nId);
		if(v!=null){
			v.setOnClickListener(clickListener);
			
		}
	}
	public static View bindView(View layout,int nId){
		View v = layout.findViewById(nId);
		return v;
	}
	
	public static void bindViewVisible(View layout,int nId,int visibility){
		View v = layout.findViewById(nId);
		if(v!=null)v.setVisibility(visibility);
	}
	
	public static TextView bindText(View layout,int nId,CharSequence msg){
		TextView v = (TextView)layout.findViewById(nId);
		if(v!=null){
			v.setText(msg);
		}
		return v;
	}
	
	public static String getText(View layout,int nId){
		View editText = bindView(layout, nId);
		if(editText==null) return null;
		if(editText instanceof EditText){
			return ((EditText)editText).getText().toString();
		}
		return null;
		
	}
}
